<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改住户信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-location-edit" th:object="${baseLocation}">
            <input name="locationId" th:field="*{locationId}" type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <input id="ltreeId" name="parentId" type="hidden" th:field="*{parentId}" />
            <div class="form-group">
                <label class="col-sm-3 control-label">上级住址：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" id="ltreeName" onclick="selectLocationTree()" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">归属部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" th:field="*{dept.deptName}" >
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">地址名称：</label>
                <div class="col-sm-8">
                    <input name="locationName" th:field="*{locationName}" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">地址类型：</label>
                <div class="col-sm-8">
                    <select name="locationType" class="form-control m-b" th:with="type=${@dict.getType('location_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{locationType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">建筑面积：</label>
                <div class="col-sm-8">
                    <input name="buildArea" th:field="*{buildArea}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">计费面积：</label>
                <div class="col-sm-8">
                    <input name="costArea" th:field="*{costArea}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">用户姓名：</label>
                <div class="col-sm-8">
                    <input name="locationHode" th:field="*{locationHode}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系方式：</label>
                <div class="col-sm-8">
                    <input name="locationContact" th:field="*{locationContact}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">用户号：</label>
                <div class="col-sm-8">
                    <input name="locationNumber" th:field="*{locationNumber}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "base/location";
        $("#form-location-edit").validate({
            onkeyup: false,
            rules:{
                locationName:{
                    remote: {
                        url: prefix + "/checkLocationNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "locationId": function() {
                                return $("#locationId").val();
                            },
                            "parentId": function() {
                                return $("input[name='parentId']").val();
                            },
                            "locationName": function() {
                                return $.common.trim($("#locationName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                orderNum:{
                    digits:true
                }
            },
            messages: {
                "locationName": {
                    remote: "住址信息已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-location-edit').serialize());
            }
        }

        /*选择住址树*/
        function selectLocationTree() {
            var ltreeId = $("#ltreeId").val();
            if(ltreeId==''){
                ltreeId = 1;
            }
            var options = {
                title: '住址选择',
                width: "380",
                url: ctx + "base/location/selectLocationTree/" + ltreeId,
                callBack: ldoSubmit
            };
            $.modal.openOptions(options);
        }

        function ldoSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowLastLevel(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#ltreeId").val(body.find('#treeId').val());
                $("#ltreeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
    </script>
</body>
</html>